package com.yidu.BusinessData.mapper;

import com.yidu.BusinessData.entity.CashAccrued;
import com.yidu.BusinessParament.entity.Cash;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author 周楠櫻木
 * @version 1.0
 * @date 2022/12/11
 */
@Mapper
public interface CashAccruedMapper {
    /**
     * 查询所有和拼接查询
     * @param map
     * @return
     */
    @Select("SELECT f.*,c.`accountName` FROM cashAccrued f LEFT JOIN cash c ON f.`cashId`=c.`cashId` where 1=1 ${term} ORDER BY f.`businessTime` limit #{page},#{row}")
    List<CashAccrued> selectCashAccrued(Map map);

    /**
     * 查询总条数
     * @param map
     * @return
     */
    @Select("select count(*) from cashAccrued where 1=1 ${term}")
    int selectCashAccruedCount(Map map);

    /**
     * 新增数据
     * @param cashAccrued
     * @return
     */
    @Insert("INSERT INTO CashAccrued VALUES(#{cashAccrued},#{fundId},#{businessTime},#{cashId},#{businessType},#{fundFlow},#{money},#{Remark})")
    int addCashAccrued(CashAccrued cashAccrued);

    /**
     * 删除数据
     * @param cashAccrued
     */
    @Delete("delete from CashAccrued where cashAccrued=#{cashAccrued}")
    void deleteCashAccrued(String cashAccrued);

    /**
     * 修改现金的应收应付
     * @param cashAccrued
     * @return
     */
    @Update("update cashAccrued set  fundId=#{fundId},businessTime=#{businessTime},cashId=#{cashId},businessType=#{businessType},fundFlow=#{fundFlow},money=#{money},Remark=#{Remark} where cashAccrued=#{cashAccrued}")
    int updateCashAccrued(CashAccrued cashAccrued);
    /**
     * 查询现金账户表
     * @return
     */
    @Select("select * from Cash")
    List<Cash> selectCash();

    /**
     * 查询现金账户总条数
     * @return
     */
    @Select("select count(*) from Cash")
    int selectCashCount();

    /**
     * 查询最大Id
     * @return
     */
    @Select("select max(cashAccrued) from cashAccrued")
    String maxSelectCashAccruedId();

    /**
     * 删除
     * @param cashAccrued
     * @return
     */
    @Delete("DELETE FROM cashAccrued WHERE fundId = #{fundId} AND businessTime= #{businessTime} AND cashId=#{cashId} and businessType=#{businessType}")
    int deleteCashAccrueds(CashAccrued cashAccrued);

    /**
     * 查询行数
     * @param cashAccrued
     * @return
     */
    @Select("select count(*) from cashAccrued where cashAccrued=#{cashAccrued}")
    int selectCashAccrueds(String cashAccrued);

    //创建一个根据实体类来删除
    void deleteNew(CashAccrued cashAccrued);
    //创建一个根据实体类来查询
    List<CashAccrued> selectNew(CashAccrued cashAccrued);

    //收益计提
    int deleteNew2(CashAccrued cashAccrued);
}
